
#define eepRom_Variable
#include "userDef.h"
U8      Test[20] =
{
    0
};


void eepRomAct( void )
{
    U8      i, ChenkSum;
    static U8 buff_eepRom[EEPROM_LEN];
    uint8_t * tempchk;

    if ( CtrlEndTime >= 20 && f_eepRomChg == 1 )
    {
        f_eepRomChg = 0;
        if ( f_eepRom == 1 )
        {
            f_eepRomR = 0;
            f_eepRomW = 1;
        }
    }

    if ( f_eepRomR == 0 && f_eepRomW == 0 )
    {
        return;
    }

    memset( buff_eepRom, 0, sizeof( buff_eepRom ) );

    /* Reset WDT */
    WDT_Restart();
    if ( f_eepRomW == 1 )
    {
        /***************************/
        /*  data write processing  */
        /***************************/

        /* Set of write data */
        buff_eepRom[0] = b_power.set;
        buff_eepRom[1] = e_mode.set;
        for ( i = 0; i < 5; i++ )
        {
            buff_eepRom[2 + i] = e_fanStep.set[i];
            buff_eepRom[7 + 2 * i] = l_tarTemp_C.set[i] &0x00ff;
            buff_eepRom[7 + 2 * i + 1] = ( l_tarTemp_C.set[i] &0xff00 ) >> 8;
            buff_eepRom[17 + 2 * i] = l_tarTemp_F.set[i] &0x00ff;
            buff_eepRom[17 + 2 * i + 1] = ( l_tarTemp_F.set[i] &0xff00 ) >> 8;
            buff_eepRom[27 + i] = e_verSw.set[i];
            buff_eepRom[32 + i] = e_horSw.set[i];
        }

        buff_eepRom[37] = b_tempFah.set;
        if ( b_light.set == 1 ) // 记忆屏显
        {
            buff_eepRom[38] = 0;        // 0开屏显
        }
        else 
        {
            buff_eepRom[38] = 1;        //1 关屏显
        }

        buff_eepRom[39] = b_health.set;
        buff_eepRom[45] = EntranceGuard.WireFlag; // 记忆线控器设置的门禁功能
        buff_eepRom[46] = EntranceGuard.RemoteFlag; // 记忆遥控器设置的门禁功能
        Test[0] = buff_eepRom[45];
        Test[1] = buff_eepRom[46];
        Test[5] = buff_eepRom[38];
        buff_eepRom[53] = f_SetNoCheckDewing;
        buff_eepRom[54] = 0;

        //buff_eepRom[54] = f_tarTempLimit; // 屏蔽掉酒店模式
        buff_eepRom[55] = setCorreck;
        if ( f_eepRomRst == ON )
        {
            if ( f_eepRom == ON )
            {
                buff_eepRom[56] = 0x81;
            }
            else 
            {
                buff_eepRom[56] = 0x80;
            }
        }

#ifdef JUMP_SELECT
        if ( f_jumpTypeRst == ON )
        {
            buff_eepRom[57] = jumpType;
            buff_eepRom[57] |= 0x80;
        }

#endif

        if ( f_quickTest == OFF )
        {
            buff_eepRom[58] = FilterCleanHour & 0x00FF;
            buff_eepRom[59] = ( FilterCleanHour & 0xFF00 ) >> 8;
        }

        buff_eepRom[60] = compOnRandomSet;
        buff_eepRom[61] = f_SetNoCheckFo;

        // buff_eepRom[62] = ; // ota
        ChenkSum = buff_eepRom[0];
        for ( i = 1; i < ( EEPROM_LEN - 2 ); i++ )
        {
            ChenkSum ^= buff_eepRom[i];
        }

        buff_eepRom[EEPROM_LEN - 2] = ChenkSum;
        buff_eepRom[EEPROM_LEN - 1] = 0x5A;
        WDT_Restart();

        // EraseSector (0x500000);
        // ProgramPage (0x500000, sizeof(buff_eepRom), (uint8_t *)buff_eepRom);
        flash_write( 0x500200, sizeof( buff_eepRom ), ( uint8_t * ) buff_eepRom );
        f_eepErr = 0;
        f_eepRomW = 0;
        count_eepRomErr = 0;
    }

    if ( f_eepRomR == 1 )
    {
        /************************/
        /* data read processing */
        /************************/
        WDT_Restart();

        /* Compare of data of read and data of write. */
        FMC->FLOPMD1 = 0x00;
        FMC->FLOPMD2 = 0x00;
        tempchk = ( uint8_t * ) 0x500200;
        for ( i = 0; i < sizeof( buff_eepRom ); i++ )
        {
            buff_eepRom[i] = *tempchk++;
        }

        ChenkSum = buff_eepRom[0];
        for ( i = 1; i < ( EEPROM_LEN - 2 ); i++ )
        {
            ChenkSum ^= buff_eepRom[i];
        }

        TEMPCHECK = ChenkSum;
        if ( ( buff_eepRom[EEPROM_LEN - 2] == ChenkSum ) && ( buff_eepRom[EEPROM_LEN - 1] == 0x5A ) )
        {
            WDT_Restart();
            set_correct( buff_eepRom[55] );
            if ( buff_eepRom[56] == 0x81 )
            {
                f_eepRomRst = ON;
                f_eepRom = ON;
            }
            else if ( buff_eepRom[56] == 0x80 )
            {
                f_eepRomRst = ON;
                f_eepRom = OFF;
            }

#ifdef JUMP_SELECT
            if ( ( buff_eepRom[57] &0x80 ) == 0x80 )
            {
                if ( buff_eepRom[57] &0x7F )
                {
                    f_jumpTypeRst = ON;
                    jumpType = buff_eepRom[57] &0x7F;
                    abiltySet();
                    fanSpeedSet();
                    swingAglSet();
                }
            }

#endif

            f_SetNoCheckDewing = buff_eepRom[53];

            //f_tarTempLimit = buff_eepRom[54]; // 屏蔽掉酒店模式
            f_SetNoCheckFo = buff_eepRom[61];
            Test[2] = buff_eepRom[45];
            Test[3] = buff_eepRom[46];
            Test[4] = buff_eepRom[38];
            EntranceGuard.WireFlag = buff_eepRom[45]; // 记忆线控器设置的门禁功能
            EntranceGuard.RemoteFlag = buff_eepRom[46]; // 记忆遥控器设置的门禁功能
            if ( f_eepRom == ON || buff_eepRom[62] == ON )
            {
                WDT_Restart();
                set_power( buff_eepRom[0] );
                if ( b_power.set == ON )
                {
                    CompOffSec = 0;
                    f_eepRomOnOff = 1;
                }

                set_mode( buff_eepRom[1] );
                for ( i = 0; i < 5; i++ )
                {
                    e_fanStep.set[i] = buff_eepRom[2 + i];
                    l_tarTemp_C.set[i] = ( buff_eepRom[7 + 2 * i + 1] << 8 ) +buff_eepRom[7 + 2 * i];
                    l_tarTemp_F.set[i] = ( buff_eepRom[17 + 2 * i + 1] << 8 ) +buff_eepRom[17 + 2 * i];
                    e_verSw.set[i] = buff_eepRom[27 + i];
                    e_horSw.set[i] = buff_eepRom[32 + i];
                }

                set_tempUnit( buff_eepRom[37] );

                //set_light( buff_eepRom[38] );
                b_light.set = buff_eepRom[38]; // 记忆屏显
                set_health( buff_eepRom[39] );
                if ( e_mode.set == MODEHEAT )
                {
                    Heat.MemFlag = 1;
                    set_heater( ON );
                    HeaterCtrl();
                }
            }

            FilterCleanHour = ( ( U16 ) buff_eepRom[59] << 8 ) +buff_eepRom[58];
            compOnRandomRun = buff_eepRom[60];
        }

        f_eepErr = 0;
        f_eepRomR = 0;
    }
}


